<?php

require_once("lib/exception/internal_error_exception.php");
require_once("lib/exception/instance_not_found_exception.php");
require_once("lib/exception/privileges_exception.php");

require_once("lib/model/action.php");
require_once("model/article_article_category/dao/article_article_category_dao_factory.php");
require_once("model/article_category/dao/article_category_dao_factory.php");
require_once("model/article_category/to/article_category_to.php");

class Remove_category_for_article_action implements Action {

	private $article_number;
	private $category_number;
	private $autor_login;
	
	public function __construct($article_number, $category_number, $autor_login) {
		
		$this->article_number = $article_number;
		$this->category_number = $category_number;
		$this->autor_login = $autor_login;
	}
	
	public function do_execute() {
		try {
			$dao = Article_category_dao_factory::singleton()->get_dao();
			$category_to = $dao->find_by_number_article_category($this->category_number);			
			if ($category_to->get_autor_login() == $this->autor_login) {
				$dao = Article_article_category_dao_factory::singleton()->get_dao();
				$dao->remove($this->article_number,$this->category_number);			
			}
			else
				throw new Privileges_exception('remove category');
		}
		catch (Instance_not_found_exception $e) {
			throw new Model_exception($e);
		}
		catch (Privileges_exception $e) {
			throw $e;
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}
	}
	
}

?>
